import tf from 'then-fs'

async function getData() {
    const str1 = await tf.readFile('./10-data.json', 'utf8')
    return JSON.parse(str1)
}

async function addData(obj) {
    try {
        const arr = await getData()
        obj.id = arr[arr.length - 1].id + 1
        arr.push(obj)
        tf.writeFile('./10-data.json', JSON.stringify(arr))
        return '添加图书成功'
    } catch {
        return '添加失败'
    }
}

addData({
    "author": "小龙龙",
    "bookname": "天降正义",
    "publisher": "河南人民出版社"
})